﻿/*
 * Created by SharpDevelop.
 * User: Christian
 * Date: 17.02.2011
 * Time: 19:26
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using ThatsMeSDK.Core;

namespace ThatsMeSDK.SDK
{
	/// <summary>
	/// Description of UserBase.
	/// </summary>
	public abstract class UserBase : IUser, IMember
	{
		public UserBase()
		{}
		
		public UserBase(string nick, string password)
		{
			Nick = nick;
			Password = password;
			LogIn();
	        LoadMyUser();
        }

	    public bool LogIn()
		{
            Token = Kernel.Authenticate(Nick, Password);
            if(!string.IsNullOrEmpty(Token))
                return true;

            return false;
		}

        public MailBox UserMailBox { get; private set; }


	    #region IMember Member

        public int Id { get; set; }

        public string Nick { get; set; }

        public DateTime Birthday { get; set; }

        public Canton.CantonShortName Canton {get;set;}
        
        public Gender Sex {get; set;}
        
        public Uri ProfilePictureUri {get; set;}
        
        public Uri ProfileUri {get; set;}

        public string RealName { get; set; }

        public List<Member> Friends { get; set; }

        private List<GalleryPicture> gallery;
        public List<GalleryPicture> Gallery
        {
            get
            {
                if (gallery == null)
                    gallery = Kernel.GetUserPics(Nick);
                return gallery;
            }
            set { gallery = value; }
        }

        public string Description { get; set; }

        private List<GalleryCategory> categories;
        public List<GalleryCategory> Categories
        {
            get
            {
                if (categories == null)
                    categories = Kernel.GetUserPicCategories(Nick);
                return categories;
            }
            set { categories = value; }
        }

	    #endregion

        #region IUser Member
        private string password;

        public string Password 
        {
        	get{return password;}
        	internal set{ password = Kernel.CalculateMD5(value);}  
        }

        #endregion

        #region IUser Member


        public string Token { get;private set;}

	    public void LoadMyUser()
        {
            UserMailBox = new MailBox(Token);
	    }

	    #endregion
	}
}
